<template>
  <div class="project-info">
    <el-row :gutter="20">
      <el-col :span="12">
        <div class="info-section">
          <h3>项目基本信息</h3>
          <div class="info-item">
            <span class="label">项目名称：</span>
            <el-input :value="formData.projectName" size="small" disabled />
          </div>
          <div class="info-item">
            <span class="label">项目标段：</span>
            <el-input :value="formData.projectSection" size="small" disabled />
          </div>
          <div class="info-item">
            <span class="label">工程名称：</span>
            <el-input :value="engineeringName" size="small" placeholder="xxxxx" disabled />
          </div>
        </div>
      </el-col>

      <el-col :span="12">
        <div class="info-section">
          <h3>计算结果</h3>
          <div class="info-item">
            <span class="label">{{ usagePhase }} kgCO2e</span>
            <el-input :value="formData.totalEmission.toFixed(2)" size="small" disabled />
          </div>
          <div class="info-item">
            <span class="label">{{ usagePhase }} kgCO2e/km</span>
            <el-input :value="getCarbonIntensity()" size="small" disabled />
          </div>
        </div>
        <h5 v-show="usagePhase === '运营维护阶段' || usagePhase === '拆除处置阶段'">
          <span style="color: red">*</span>
          <span style="color: #2c3e50">
          无{{ usagePhase.replace('阶段', '') }}数据时，碳排放量以该工程建造阶段碳排放总量的10%计入
          </span>
        </h5>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  props: {
    projectData: {
      type: Object,
      default: () => ({
        projectName: 'XXX',
        projectSection: 'xxx',
        mileage: 1,
        totalEmission: 1,
      })
    },
    engineeringNamesData: {
      type: String,
      default: ""
    },
    usagePhase: {
      type: String,
      default: ""
    }
  },

  data() {
    return {
      formData: { ...this.projectData },
      engineeringName: this.engineeringNamesData
    }
  },

  methods: {
    getCarbonIntensity() {
      return (this.formData.totalEmission / this.formData.mileage).toFixed(4)
    },
  },

  watch: {
    projectData: {
      deep: true,
      handler(newVal) {
        this.formData = { ...newVal };
      }
    },
    engineeringNamesData: {
      deep: true,
      handler(newVal) {
        this.engineeringNames = [...newVal];
      }
    }
  }
}
</script>

<style scoped>
.project-info {
  margin-bottom: 24px;
  padding: 20px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.info-section {
  margin-bottom: 20px;
  width: 60%;
}

.info-item {
  margin: 20px 0;
}

.label {
  min-width: 240px;
  text-align: right;
  margin-right: 10px;
  color: #666;
}

.project-names {
  margin-top: 20px;
}
</style>
